Set lang in api createaccount regardless of $wgLoginLanguageSelector
authorBrian Wolff <bawolff+wn@gmail.com>
Sat, 9 Mar 2013 10:57:07 +0000 (06:57 -0400)
committerBrian Wolff <bawolff+wn@gmail.com>
Wed, 27 Mar 2013 11:41:20 +0000 (08:41 -0300)
$wgLoginLanguageSelector is related to how the interface of
special:userlogin works. It doesn't make sense to listen to it
in the api module

Also throw error if invalid lang code is specified (for sanity)

Change-Id: Ibf72fd5a318cadc450b3b579757ee8145864a27a

includes/api/ApiCreateAccount.php

index 55c60cc..1eb1aa5 100644 (file)
@@ -54,6 +54,10 @@ class ApiCreateAccount extends ApiBase {
                        $this->dieUsageMsg( 'noemail' );
                }
 
+               if ( $params['language'] && !Language::isSupportedLanguage( $params['language'] ) ) {
+                       $this->dieUsage( 'Invalid language parameter', 'langinvalid' );
+               }
+
                $context = new DerivativeContext( $this->getContext() );
                $context->setRequest( new DerivativeRequest(
                        $this->getContext()->getRequest(),
@@ -80,12 +84,10 @@ class ApiCreateAccount extends ApiBase {
                $result = array();
                if( $status->isGood() ) {
                        // Success!
+                       global $wgEmailAuthentication;
                        $user = $status->getValue();
 
-                       // If we showed up language selection links, and one was in use, be
-                       // smart (and sensible) and save that language as the user's preference
-                       global $wgLoginLanguageSelector, $wgEmailAuthentication;
-                       if( $wgLoginLanguageSelector && $params['language'] ) {
+                       if( $params['language'] ) {
                                $user->setOption( 'language', $params['language'] );
                        }
 
@@ -275,6 +277,10 @@ class ApiCreateAccount extends ApiBase {
                        'code' => 'aborted',
                        'info' => 'Account creation aborted by hook (info may vary)'
                );
+               $errors[] = array(
+                       'code' => 'langinvalid',
+                       'info' => 'Invalid language parameter'
+               );
 
                // 'passwordtooshort' has parameters. :(
                global $wgMinimalPasswordLength;